package jsyntaxpane.util.intellisense.bsh;

import java.lang.reflect.Member;
import java.lang.reflect.Modifier;

/**
 * @author takeshi
 */
public class NamedSyntheticMember implements Member {
    private final String name;

    private final Class<?> host;

    /**
     * @param name {@link String}
     */
    public NamedSyntheticMember(String name) {
        this(name, Object.class);
    }

    /**
     * @param name String
     * @param host host
     */
    public NamedSyntheticMember(String name, Class<?> host) {
        super();
        this.name = name;
        this.host = host;
    }

    /**
     * {@inheritDoc}
     */
    public final Class<?> getDeclaringClass() {
        return host;
    }

    /**
     * {@inheritDoc}
     */
    public final int getModifiers() {
        return Modifier.PUBLIC | Modifier.STATIC;
    }

    /**
     * {@inheritDoc}
     */
    public final boolean isSynthetic() {
        return true;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public String toString() {
        return getName();
    }

    /**
     * {@inheritDoc}
     */
    public String getName() {
        return name;
    }

    /**
    * {@inheritDoc}
    */
    
    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((host == null) ? 0 : host.hashCode());
        result = prime * result + ((name == null) ? 0 : name.hashCode());
        return result;
    }

    /**
    * {@inheritDoc}
    */
    
    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        NamedSyntheticMember other = (NamedSyntheticMember) obj;
        if (host == null) {
            if (other.host != null) {
                return false;
            }
        } else if (!host.equals(other.host)) {
            return false;
        }
        if (name == null) {
            if (other.name != null) {
                return false;
            }
        } else if (!name.equals(other.name)) {
            return false;
        }
        return true;
    }
}